import mmap


file_path = "data.bin"

with open(file_path, "r+b") as f:

    # 映射整个文件到内存
    mm = mmap.mmap(f.fileno(), 0)

    # 读取数据（需解码字节为字符串）
    mm.seek(0)
    data = mm.read(len("Hello from Process A".encode())).decode()
    print(f"Received: {data}")  # 输出: Hello from Process A

    # 关闭映射和锁
    mm.close()
